<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>选择照片 | 新浪微博开发笔记</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.1.0">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
    

        
    
    
    <link rel="next" href="../compose/post status.html" />
    
    
    <link rel="prev" href="../compose/setup ui.html" />
    

        
    </head>
    <body>
        
        
    <div class="book" data-level="0.10.2" data-basepath=".." data-revision="Wed Oct 14 2015 07:05:46 GMT+0800 (CST)">
    

<div class="book-summary">
    <div class="book-search">
        <input type="text" placeholder="Type to search" class="form-control" />
    </div>
    <ul class="summary">
        
        
        
        

        

        
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                        <i class="fa fa-check"></i>
                        
                        新浪微博笔记
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.1" data-path="project init/prepare project.html">
            
                
                    <a href="../project init/prepare project.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.1.</b>
                        
                        准备工作
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.1.1" data-path="project init/project deploy.html">
            
                
                    <a href="../project init/project deploy.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.1.1.</b>
                        
                        项目部署
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.1.2" data-path="project init/project settings.html">
            
                
                    <a href="../project init/project settings.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.1.2.</b>
                        
                        项目设置
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.1.3" data-path="project init/confirm architecture.html">
            
                
                    <a href="../project init/confirm architecture.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.1.3.</b>
                        
                        架构确定
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.1.4" data-path="project init/mvvm.html">
            
                
                    <a href="../project init/mvvm.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.1.4.</b>
                        
                        MVVM
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.2" data-path="create project/readme.html">
            
                
                    <a href="../create project/readme.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.2.</b>
                        
                        项目搭建
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.2.1" data-path="create project/create files.html">
            
                
                    <a href="../create project/create files.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.2.1.</b>
                        
                        创建文件
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.2.2" data-path="create project/add child controllers.html">
            
                
                    <a href="../create project/add child controllers.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.2.2.</b>
                        
                        添加子控制器
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.2.3" data-path="create project/custom main tabbar.html">
            
                
                    <a href="../create project/custom main tabbar.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.2.3.</b>
                        
                        自定义 TabBar
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.2.4" data-path="create project/summary.html">
            
                
                    <a href="../create project/summary.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.2.4.</b>
                        
                        阶段性小结
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.3" data-path="visitor/readme.html">
            
                
                    <a href="../visitor/readme.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.3.</b>
                        
                        访客视图
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.3.1" data-path="visitor/base table view controller.html">
            
                
                    <a href="../visitor/base table view controller.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.3.1.</b>
                        
                        表格视图控制器基类
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.3.2" data-path="visitor/visitor login view.html">
            
                
                    <a href="../visitor/visitor login view.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.3.2.</b>
                        
                        用户登录视图
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.3.3" data-path="visitor/setup login info.html">
            
                
                    <a href="../visitor/setup login info.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.3.3.</b>
                        
                        设置未登录信息
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.3.4" data-path="visitor/home animation.html">
            
                
                    <a href="../visitor/home animation.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.3.4.</b>
                        
                        首页动画
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.3.5" data-path="visitor/login buttons delegate.html">
            
                
                    <a href="../visitor/login buttons delegate.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.3.5.</b>
                        
                        登录&amp;注册代理回调
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.3.6" data-path="visitor/appearance.html">
            
                
                    <a href="../visitor/appearance.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.3.6.</b>
                        
                        导航栏全局外观
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.4" data-path="frameworks/readme.html">
            
                
                    <a href="../frameworks/readme.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.4.</b>
                        
                        第三方框架
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.4.1" data-path="frameworks/afnetworking.html">
            
                
                    <a href="../frameworks/afnetworking.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.4.1.</b>
                        
                        AFNetworking
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.4.2" data-path="frameworks/svprogresshud sdwebimage.html">
            
                
                    <a href="../frameworks/svprogresshud sdwebimage.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.4.2.</b>
                        
                        SVProgressHUD 和 SDWebImage
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.4.3" data-path="frameworks/snapkit.html">
            
                
                    <a href="../frameworks/snapkit.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.4.3.</b>
                        
                        SnapKit
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.5" data-path="oauth/readme.html">
            
                
                    <a href="../oauth/readme.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.5.</b>
                        
                        OAuth
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.5.1" data-path="oauth/register app.html">
            
                
                    <a href="../oauth/register app.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.5.1.</b>
                        
                        注册应用程序
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.5.2" data-path="oauth/load oauth page.html">
            
                
                    <a href="../oauth/load oauth page.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.5.2.</b>
                        
                        加载授权页面
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.6" data-path="access token/readme.html">
            
                
                    <a href="../access token/readme.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.6.</b>
                        
                        Access Token
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.6.1" data-path="access token/load access token.html">
            
                
                    <a href="../access token/load access token.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.6.1.</b>
                        
                        加载 AccessToken
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.6.2" data-path="access token/user account.html">
            
                
                    <a href="../access token/user account.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.6.2.</b>
                        
                        用户账户模型
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.6.3" data-path="access token/expires date.html">
            
                
                    <a href="../access token/expires date.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.6.3.</b>
                        
                        过期日期
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.6.4" data-path="access token/load user info.html">
            
                
                    <a href="../access token/load user info.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.6.4.</b>
                        
                        加载用户信息
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.6.5" data-path="access token/archive user account.html">
            
                
                    <a href="../access token/archive user account.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.6.5.</b>
                        
                        归档 &amp; 解档
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.6.6" data-path="access token/view model.html">
            
                
                    <a href="../access token/view model.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.6.6.</b>
                        
                        视图模型
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.6.7" data-path="access token/error enum.html">
            
                
                    <a href="../access token/error enum.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.6.7.</b>
                        
                        自定义错误枚举
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.7" data-path="newfeature/index.html">
            
                
                    <a href="../newfeature/index.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.7.</b>
                        
                        新特性和欢迎界面
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.7.1" data-path="newfeature/newfeature.html">
            
                
                    <a href="../newfeature/newfeature.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.7.1.</b>
                        
                        新特性
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.7.2" data-path="newfeature/welcome.html">
            
                
                    <a href="../newfeature/welcome.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.7.2.</b>
                        
                        欢迎界面
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.7.3" data-path="newfeature/switch vc.html">
            
                
                    <a href="../newfeature/switch vc.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.7.3.</b>
                        
                        切换界面
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.8" data-path="homepage/index.html">
            
                
                    <a href="../homepage/index.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.</b>
                        
                        首页布局
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.8.1" data-path="homepage/status model.html">
            
                
                    <a href="../homepage/status model.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.1.</b>
                        
                        微博数据模型
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.8.2" data-path="homepage/tableview show data.html">
            
                
                    <a href="../homepage/tableview show data.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.2.</b>
                        
                        显示表格数据
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.8.3" data-path="homepage/user model.html">
            
                
                    <a href="../homepage/user model.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.3.</b>
                        
                        用户模型
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.8.4" data-path="homepage/status view model.html">
            
                
                    <a href="../homepage/status view model.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.4.</b>
                        
                        微博视图模型
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.8.5" data-path="homepage/custom cell.html">
            
                
                    <a href="../homepage/custom cell.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.5.</b>
                        
                        自定义 Cell
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.8.6" data-path="homepage/prepare for pictureview.html">
            
                
                    <a href="../homepage/prepare for pictureview.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.6.</b>
                        
                        配图视图准备
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.8.7" data-path="homepage/picture view.html">
            
                
                    <a href="../homepage/picture view.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.7.</b>
                        
                        配图视图
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.8.8" data-path="homepage/retweeted_status.html">
            
                
                    <a href="../homepage/retweeted_status.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.8.</b>
                        
                        转发微博
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.8.9" data-path="homepage/single picture.html">
            
                
                    <a href="../homepage/single picture.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.9.</b>
                        
                        单张图片比例
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.9" data-path="refresh/index.html">
            
                
                    <a href="../refresh/index.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.9.</b>
                        
                        刷新
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.9.1" data-path="refresh/pullup view.html">
            
                
                    <a href="../refresh/pullup view.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.9.1.</b>
                        
                        上拉刷新控件
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.9.2" data-path="refresh/refresh data.html">
            
                
                    <a href="../refresh/refresh data.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.9.2.</b>
                        
                        刷新数据
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.9.3" data-path="refresh/pulldown tips.html">
            
                
                    <a href="../refresh/pulldown tips.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.9.3.</b>
                        
                        下拉刷新提示
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.10" data-path="compose/index.html">
            
                
                    <a href="../compose/index.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.10.</b>
                        
                        发布微博
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.10.1" data-path="compose/setup ui.html">
            
                
                    <a href="../compose/setup ui.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.10.1.</b>
                        
                        搭建界面
                    </a>
                
            
            
        </li>
    
        <li class="chapter active" data-level="0.10.2" data-path="compose/select picture.html">
            
                
                    <a href="../compose/select picture.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.10.2.</b>
                        
                        选择照片
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.10.3" data-path="compose/post status.html">
            
                
                    <a href="../compose/post status.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.10.3.</b>
                        
                        发布微博
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.11" data-path="emoticon/index.html">
            
                
                    <a href="../emoticon/index.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.</b>
                        
                        表情键盘
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.11.1" data-path="emoticon/prepare ui.html">
            
                
                    <a href="../emoticon/prepare ui.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.1.</b>
                        
                        准备界面
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.11.2" data-path="emoticon/load bundle data.html">
            
                
                    <a href="../emoticon/load bundle data.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.2.</b>
                        
                        加载模型数据
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.11.3" data-path="emoticon/show emoticon.html">
            
                
                    <a href="../emoticon/show emoticon.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.3.</b>
                        
                        显示表情符号
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.11.4" data-path="emoticon/upgrade model.html">
            
                
                    <a href="../emoticon/upgrade model.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.4.</b>
                        
                        提升数据模型
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.11.5" data-path="emoticon/selected emoticon.html">
            
                
                    <a href="../emoticon/selected emoticon.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.5.</b>
                        
                        选中表情事件
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.11.6" data-path="emoticon/attribute text.html">
            
                
                    <a href="../emoticon/attribute text.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.6.</b>
                        
                        属性文本
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.11.7" data-path="emoticon/merge_emoticon.html">
            
                
                    <a href="../emoticon/merge_emoticon.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.7.</b>
                        
                        整合到新浪微博
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.11.8" data-path="emoticon/favorite emoticon.html">
            
                
                    <a href="../emoticon/favorite emoticon.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.8.</b>
                        
                        内存表情排序
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.12" data-path="sqlite/index.html">
            
                
                    <a href="../sqlite/index.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.12.</b>
                        
                        数据缓存
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.12.1" data-path="sqlite/data model.html">
            
                
                    <a href="../sqlite/data model.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.12.1.</b>
                        
                        数据模型设计
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.12.2" data-path="sqlite/statusdal.html">
            
                
                    <a href="../sqlite/statusdal.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.12.2.</b>
                        
                        数据访问层
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.12.3" data-path="sqlite/clean cache.html">
            
                
                    <a href="../sqlite/clean cache.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.12.3.</b>
                        
                        清理数据缓存
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.13" data-path="ending/index.html">
            
                
                    <a href="../ending/index.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.13.</b>
                        
                        微博收尾
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.13.1" data-path="ending/status create at.html">
            
                
                    <a href="../ending/status create at.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.13.1.</b>
                        
                        微博时间
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.13.2" data-path="ending/regex.html">
            
                
                    <a href="../ending/regex.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.13.2.</b>
                        
                        正则表达式
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.13.3" data-path="ending/emoticon string.html">
            
                
                    <a href="../ending/emoticon string.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.13.3.</b>
                        
                        表情字符串
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.13.4" data-path="ending/fflabel.html">
            
                
                    <a href="../ending/fflabel.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.13.4.</b>
                        
                        FFLabel
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.13.5" data-path="ending/textkit.html">
            
                
                    <a href="../ending/textkit.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.13.5.</b>
                        
                        TextKit
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="0.14" data-path="appendix/readme.html">
            
                
                    <a href="../appendix/readme.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.14.</b>
                        
                        附录
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.14.1" data-path="appendix/image assets.html">
            
                
                    <a href="../appendix/image assets.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.14.1.</b>
                        
                        图片素材
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.14.2" data-path="appendix/cocoa pod.html">
            
                
                    <a href="../appendix/cocoa pod.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.14.2.</b>
                        
                        cocoa pod
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.14.3" data-path="appendix/singleton.html">
            
                
                    <a href="../appendix/singleton.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.14.3.</b>
                        
                        单例
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.14.4" data-path="appendix/swift_vs_oc.html">
            
                
                    <a href="../appendix/swift_vs_oc.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.14.4.</b>
                        
                        为什么要学习 Swift
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.14.5" data-path="appendix/emoji.html">
            
                
                    <a href="../appendix/emoji.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.14.5.</b>
                        
                        emoji
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    


        
        <li class="divider"></li>
        <li>
            <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                Published with GitBook
            </a>
        </li>
        
    </ul>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="Table of Contents"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="Search"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="Font Settings"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">Serif</button>
        <button type="button" data-font="1" class="button">Sans</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">White</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">Sepia</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">Night</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="Share"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">
                    Share on Twitter
                </button>
                <button type="button" data-sharing="google-plus" class="button">
                    Share on Google
                </button>
                <button type="button" data-sharing="facebook" class="button">
                    Share on Facebook
                </button>
                <button type="button" data-sharing="weibo" class="button">
                    Share on Weibo
                </button>
                <button type="button" data-sharing="instapaper" class="button">
                    Share on Instapaper
                </button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Google"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
    
    
    


    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >新浪微博开发笔记</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="%E9%80%89%E6%8B%A9%E7%85%A7%E7%89%87">&#x9009;&#x62E9;&#x7167;&#x7247;</h1>
<h2 id="%E7%9B%AE%E6%A0%87">&#x76EE;&#x6807;</h2>
<ul>
<li>&#x5728;&#x72EC;&#x7ACB;&#x7684;&#x9879;&#x76EE;&#x4E2D;&#x5F00;&#x53D1;&#x72EC;&#x7ACB;&#x7684;&#x529F;&#x80FD;</li>
<li>&#x5F00;&#x53D1;&#x5B8C;&#x6BD5;&#x540E;&#x518D;&#x6574;&#x5408;&#x5230;&#x73B0;&#x6709;&#x9879;&#x76EE;&#x4E2D;</li>
<li>&#x63D0;&#x9AD8;&#x5DE5;&#x4F5C;&#x6548;&#x7387;&#xFF0C;&#x4E13;&#x6CE8;&#x5F00;&#x53D1;&#x54C1;&#x8D28; &#x1F604;</li>
<li>&#x9009;&#x62E9;&#x7167;&#x7247;</li>
<li>&#x91CD;&#x5EFA;&#x63A7;&#x4EF6;&#x5E03;&#x5C40;</li>
</ul>
<h2 id="%E9%A1%B9%E7%9B%AE%E5%87%86%E5%A4%87">&#x9879;&#x76EE;&#x51C6;&#x5907;</h2>
<ul>
<li>&#x65B0;&#x5EFA;&#x7A7A;&#x767D;&#x9879;&#x76EE;</li>
<li>&#x5220;&#x9664;&#x65E0;&#x7528;&#x6587;&#x4EF6;<ul>
<li>ViewController.swift</li>
<li>Main.storyboard</li>
</ul>
</li>
<li>&#x4FEE;&#x6539;&#x542F;&#x52A8;&#x9009;&#x9879;&#xFF0C;&#x5220;&#x9664; Main</li>
<li>&#x65B0;&#x5EFA;&#x6587;&#x4EF6;&#x5939; <code>PictureSelector</code></li>
<li>&#x65B0;&#x5EFA; <code>PictureSelectorViewController</code> &#x7EE7;&#x627F;&#x81EA; <code>UICollectionViewController</code></li>
<li>&#x5728; <code>AppDelegate</code> &#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">application</span><span class="hljs-params">(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)</span> -&gt; <span class="hljs-title">Bool</span> </span>{

    window = <span class="hljs-type">UIWindow</span>(frame: <span class="hljs-type">UIScreen</span>.mainScreen().bounds)
    window?.backgroundColor = <span class="hljs-type">UIColor</span>.whiteColor()
    window?.rootViewController = <span class="hljs-type">PictureSelectorViewController</span>()

    window?.makeKeyAndVisible()

    <span class="hljs-keyword">return</span> <span class="hljs-built_in">true</span>
}
</code></pre>
<blockquote>
<p>&#x8FD0;&#x884C;&#x6D4B;&#x8BD5;</p>
</blockquote>
<h2 id="%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0">&#x4EE3;&#x7801;&#x5B9E;&#x73B0;</h2>
<h3 id="%E8%AE%BE%E7%BD%AE%E5%B8%83%E5%B1%80">&#x8BBE;&#x7F6E;&#x5E03;&#x5C40;</h3>
<ul>
<li>&#x6DFB;&#x52A0;&#x63A7;&#x5236;&#x5668;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x7B80;&#x5316;&#x5916;&#x90E8;&#x8C03;&#x7528;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x53EF;&#x91CD;&#x7528;&#x6807;&#x8BC6;&#x7B26;&#x53F7;</span>
private <span class="hljs-keyword">let</span> <span class="hljs-type">WBPictureSelectorViewCellID</span> = <span class="hljs-string">&quot;WBPictureSelectorViewCellID&quot;</span>

<span class="hljs-comment">/// &#x7167;&#x7247;&#x9009;&#x62E9;&#x63A7;&#x5236;&#x5668;</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PictureSelectorViewController</span>: <span class="hljs-title">UICollectionViewController</span> </span>{

    <span class="hljs-comment">// MARK: - &#x6784;&#x9020;&#x51FD;&#x6570;</span>
    <span class="hljs-keyword">init</span>() {
        <span class="hljs-keyword">let</span> layout = <span class="hljs-type">UICollectionViewFlowLayout</span>()

        <span class="hljs-keyword">super</span>.<span class="hljs-keyword">init</span>(collectionViewLayout: layout)
    }

    required <span class="hljs-keyword">init</span>?(coder aDecoder: <span class="hljs-type">NSCoder</span>) {
        fatalError(<span class="hljs-string">&quot;init(coder:) has not been implemented&quot;</span>)
    }

    <span class="hljs-keyword">override</span> <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">viewDidLoad</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">super</span>.viewDidLoad()

        <span class="hljs-comment">// &#x6CE8;&#x518C;&#x53EF;&#x91CD;&#x7528; Cell</span>
        <span class="hljs-keyword">self</span>.collectionView!.registerClass(<span class="hljs-type">UICollectionViewCell</span>.<span class="hljs-keyword">self</span>,
            forCellWithReuseIdentifier: <span class="hljs-type">WBPictureSelectorViewCellID</span>)
    }
}
</code></pre>
<ul>
<li>&#x8BBE;&#x7F6E;&#x80CC;&#x666F;&#x989C;&#x8272;</li>
</ul>
<pre><code class="lang-swift">collectionView?.backgroundColor = <span class="hljs-type">UIColor</span>.lightGrayColor()
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#x5728; <code>CollectionViewController</code> &#x4E2D;&#xFF0C;<code>collectionView</code> &#x4E0D;&#x662F; <code>view</code></p>
</blockquote>
<ul>
<li>&#x4FEE;&#x6539;&#x6570;&#x636E;&#x6E90;&#x65B9;&#x6CD5;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// MARK: &#x6570;&#x636E;&#x6E90;</span>
<span class="hljs-keyword">override</span> <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">collectionView</span><span class="hljs-params">(collectionView: UICollectionView, numberOfItemsInSection section: Int)</span> -&gt; <span class="hljs-title">Int</span> </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>
}

<span class="hljs-keyword">override</span> <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">collectionView</span><span class="hljs-params">(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath)</span> -&gt; <span class="hljs-title">UICollectionViewCell</span> </span>{
    <span class="hljs-keyword">let</span> cell = collectionView.dequeueReusableCellWithReuseIdentifier(<span class="hljs-type">WBPictureSelectorViewCellID</span>, forIndexPath: indexPath)

    <span class="hljs-comment">// Configure the cell</span>
    cell.backgroundColor = <span class="hljs-type">UIColor</span>.redColor()

    <span class="hljs-keyword">return</span> cell
}
</code></pre>
<ul>
<li>&#x8BBE;&#x7F6E; cell &#x5C3A;&#x5BF8;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">init</span>() {
    <span class="hljs-keyword">let</span> layout = <span class="hljs-type">UICollectionViewFlowLayout</span>()
    <span class="hljs-comment">// &#x5C4F;&#x5E55;&#x8D8A;&#x5927;&#xFF0C;&#x663E;&#x793A;&#x7684;&#x5185;&#x5BB9;&#x5E94;&#x8BE5;&#x8D8A;&#x591A;</span>
    layout.itemSize = <span class="hljs-type">CGSize</span>(width: <span class="hljs-number">80</span>, height: <span class="hljs-number">80</span>)
    layout.sectionInset = <span class="hljs-type">UIEdgeInsets</span>(top: <span class="hljs-number">20</span>, <span class="hljs-keyword">left</span>: <span class="hljs-number">20</span>, bottom: <span class="hljs-number">0</span>, <span class="hljs-keyword">right</span>: <span class="hljs-number">20</span>)

    <span class="hljs-keyword">super</span>.<span class="hljs-keyword">init</span>(collectionViewLayout: layout)
}
</code></pre>
<blockquote>
<p>&#x4ECE; iPhone 6 &#x5F00;&#x59CB;&#xFF0C;&#x5C31;&#x9700;&#x8981;&#x8003;&#x8651;&#x8D8A;&#x5927;&#x7684;&#x5C4F;&#x5E55;&#x663E;&#x793A;&#x8D8A;&#x591A;&#x7684;&#x5185;&#x5BB9;</p>
</blockquote>
<h3 id="%E8%87%AA%E5%AE%9A%E4%B9%89-cell">&#x81EA;&#x5B9A;&#x4E49; Cell</h3>
<ul>
<li>&#x6DFB;&#x52A0;&#x7D20;&#x6750;</li>
<li>&#x5C06; <code>UIButton+Extension.swift</code> &#x62D6;&#x62FD;&#x5230;&#x9879;&#x76EE;&#x4E2D;</li>
<li><p>&#x5C06; <code>SnapKit</code> &#x7684; <code>Source</code> &#x6587;&#x4EF6;&#x5939;&#x62D6;&#x62FD;&#x5230;&#x9879;&#x76EE;&#x4E2D;</p>
</li>
<li><p>&#x81EA;&#x5B9A;&#x4E49; Cell</p>
</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x7167;&#x7247;&#x9009;&#x62E9;&#x5355;&#x5143;&#x683C;</span>
private <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PictureSelectorViewCell</span>: <span class="hljs-title">UICollectionViewCell</span> </span>{

    <span class="hljs-comment">// MARK: - &#x6784;&#x9020;&#x51FD;&#x6570;</span>
    <span class="hljs-keyword">override</span> <span class="hljs-keyword">init</span>(frame: <span class="hljs-type">CGRect</span>) {
        <span class="hljs-keyword">super</span>.<span class="hljs-keyword">init</span>(frame: frame)

        setupUI()
    }

    required <span class="hljs-keyword">init</span>?(coder aDecoder: <span class="hljs-type">NSCoder</span>) {
        fatalError(<span class="hljs-string">&quot;init(coder:) has not been implemented&quot;</span>)
    }

    <span class="hljs-comment">/// &#x8BBE;&#x7F6E;&#x754C;&#x9762;</span>
    private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">setupUI</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-comment">// &#x6DFB;&#x52A0;&#x63A7;&#x4EF6;</span>
        contentView.addSubview(addButton)
        contentView.addSubview(removeButton)

        <span class="hljs-comment">// &#x81EA;&#x52A8;&#x5E03;&#x5C40;</span>
        addButton.snp_makeConstraints { (make) -&gt; <span class="hljs-type">Void</span> <span class="hljs-keyword">in</span>
            make.edges.equalTo(contentView.snp_edges)
        }
        removeButton.snp_makeConstraints { (make) -&gt; <span class="hljs-type">Void</span> <span class="hljs-keyword">in</span>
            make.top.equalTo(contentView.snp_top)
            make.<span class="hljs-keyword">right</span>.equalTo(contentView.snp_right)
        }
    }

    <span class="hljs-comment">// MARK: - &#x61D2;&#x52A0;&#x8F7D;&#x63A7;&#x4EF6;</span>
    <span class="hljs-comment">/// &#x6DFB;&#x52A0;&#x6309;&#x94AE;</span>
    private <span class="hljs-keyword">var</span> addButton = <span class="hljs-type">UIButton</span>(imageName: <span class="hljs-string">&quot;compose_pic_add&quot;</span>, backImageName: <span class="hljs-built_in">nil</span>)
    <span class="hljs-comment">/// &#x5220;&#x9664;&#x6309;&#x94AE;</span>
    private <span class="hljs-keyword">var</span> removeButton = <span class="hljs-type">UIButton</span>(imageName: <span class="hljs-string">&quot;compose_photo_close&quot;</span>, backImageName: <span class="hljs-built_in">nil</span>)
}
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x6CE8;&#x518C;&#x7684; Cell</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x6CE8;&#x518C;&#x53EF;&#x91CD;&#x7528; Cell</span>
collectionView!.registerClass(<span class="hljs-type">PictureSelectorViewCell</span>.<span class="hljs-keyword">self</span>,
    forCellWithReuseIdentifier: <span class="hljs-type">WBPictureSelectorViewCellID</span>)
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x6570;&#x636E;&#x6E90;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">let</span> cell = collectionView.dequeueReusableCellWithReuseIdentifier(<span class="hljs-type">WBPictureSelectorViewCellID</span>, forIndexPath: indexPath) <span class="hljs-keyword">as</span>! <span class="hljs-type">PictureSelectorViewCell</span>
</code></pre>
<ul>
<li>&#x6309;&#x94AE;&#x76D1;&#x542C;&#x65B9;&#x6CD5;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// MARK: - &#x76D1;&#x542C;&#x65B9;&#x6CD5;</span>
<span class="hljs-comment">/// &#x6DFB;&#x52A0;&#x7167;&#x7247;</span>
<span class="hljs-preprocessor">@objc</span> private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">addPicture</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#x6DFB;&#x52A0;&#x7167;&#x7247;&quot;</span>)
}

<span class="hljs-comment">/// &#x5220;&#x9664;&#x7167;&#x7247;</span>
<span class="hljs-preprocessor">@objc</span> private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">removePicture</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#x5220;&#x9664;&#x7167;&#x7247;&quot;</span>)
}
</code></pre>
<ul>
<li>&#x6DFB;&#x52A0;&#x76D1;&#x542C;&#x65B9;&#x6CD5;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x76D1;&#x542C;&#x65B9;&#x6CD5;</span>
addButton.addTarget(<span class="hljs-keyword">self</span>, action: <span class="hljs-string">&quot;addPicture&quot;</span>, forControlEvents: .<span class="hljs-type">TouchUpInside</span>)
removeButton.addTarget(<span class="hljs-keyword">self</span>, action: <span class="hljs-string">&quot;removePicture&quot;</span>, forControlEvents: .<span class="hljs-type">TouchUpInside</span>)
</code></pre>
<h3 id="%E5%88%A9%E7%94%A8%E4%BB%A3%E7%90%86%E4%BC%A0%E9%80%92%E6%8C%89%E9%92%AE%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6">&#x5229;&#x7528;&#x4EE3;&#x7406;&#x4F20;&#x9012;&#x6309;&#x94AE;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;</h3>
<ul>
<li>&#x5B9A;&#x4E49;&#x534F;&#x8BAE;&#x4F20;&#x9012;&#x6D88;&#x606F;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x7167;&#x7247;&#x9009;&#x62E9;&#x5355;&#x5143;&#x683C;&#x4EE3;&#x7406;</span>
private <span class="hljs-class"><span class="hljs-keyword">protocol</span> <span class="hljs-title">PictureSelectorViewCellDelegate</span>: <span class="hljs-title">NSObjectProtocol</span> </span>{
    <span class="hljs-comment">/// &#x6DFB;&#x52A0;&#x7167;&#x7247;</span>
    <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">pictureSelectorViewCellDidAdd</span><span class="hljs-params">(cell: PictureSelectorViewCell)</span>
    /// &#x5220;&#x9664;&#x7167;&#x7247;
    <span class="hljs-title">func</span> <span class="hljs-title">pictureSelectorViewCellDidRemove</span><span class="hljs-params">(cell: PictureSelectorViewCell)</span>
}
</span></code></pre>
<ul>
<li>&#x8BBE;&#x7F6E;&#x4EE3;&#x7406;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x7167;&#x7247;&#x9009;&#x62E9;&#x4EE3;&#x7406;</span>
<span class="hljs-keyword">weak</span> <span class="hljs-keyword">var</span> pictureDelegate: <span class="hljs-type">PictureSelectorViewCellDelegate</span>?
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x76D1;&#x542C;&#x65B9;&#x6CD5;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// MARK: - &#x76D1;&#x542C;&#x65B9;&#x6CD5;</span>
<span class="hljs-comment">/// &#x6DFB;&#x52A0;&#x7167;&#x7247;</span>
<span class="hljs-preprocessor">@objc</span> private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">addPicture</span><span class="hljs-params">()</span> </span>{
    pictureDelegate?.pictureSelectorViewCellDidAdd(<span class="hljs-keyword">self</span>)
}

<span class="hljs-comment">/// &#x5220;&#x9664;&#x7167;&#x7247;</span>
<span class="hljs-preprocessor">@objc</span> private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">removePicture</span><span class="hljs-params">()</span> </span>{
    pictureDelegate?.pictureSelectorViewCellDidRemove(<span class="hljs-keyword">self</span>)
}
</code></pre>
<ul>
<li>&#x5728; <code>extension</code> &#x4E2D;&#x5B9E;&#x73B0;&#x534F;&#x8BAE;&#x65B9;&#x6CD5;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// MARK: - PictureSelectorViewCellDelegate</span>
<span class="hljs-class"><span class="hljs-keyword">extension</span> <span class="hljs-title">PictureSelectorViewController</span>: <span class="hljs-title">PictureSelectorViewCellDelegate</span> </span>{
    private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">pictureSelectorViewCellDidAdd</span><span class="hljs-params">(cell: PictureSelectorViewCell)</span> </span>{
        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#x6DFB;&#x52A0;&#x7167;&#x7247;&quot;</span>)
    }

    private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">pictureSelectorViewCellDidRemove</span><span class="hljs-params">(cell: PictureSelectorViewCell)</span> </span>{
        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#x5220;&#x9664;&#x7167;&#x7247;&quot;</span>)
    }
}
</code></pre>
<ul>
<li>&#x5728;&#x6570;&#x636E;&#x6E90;&#x65B9;&#x6CD5;&#x4E2D;&#x8BBE;&#x7F6E;&#x4EE3;&#x7406;</li>
</ul>
<pre><code class="lang-swift">cell.pictureDelegate = <span class="hljs-keyword">self</span>
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5982;&#x679C;&#x534F;&#x8BAE;&#x662F;&#x79C1;&#x6709;&#x7684;&#xFF0C;&#x90A3;&#x4E48;&#x534F;&#x8BAE;&#x65B9;&#x6CD5;&#x4E5F;&#x5FC5;&#x987B;&#x662F;&#x79C1;&#x6709;&#x7684;</p>
</blockquote>
<h3 id="%E9%80%89%E6%8B%A9%E7%85%A7%E7%89%87">&#x9009;&#x62E9;&#x7167;&#x7247;</h3>
<ul>
<li>&#x5224;&#x65AD;&#x662F;&#x5426;&#x652F;&#x6301;&#x8BBF;&#x95EE;&#x76F8;&#x518C;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x6DFB;&#x52A0;&#x7167;&#x7247;</span>
private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">pictureSelectorViewCellDidAdd</span><span class="hljs-params">(cell: PictureSelectorViewCell)</span> </span>{
    <span class="hljs-comment">// &#x5224;&#x65AD;&#x662F;&#x5426;&#x652F;&#x6301;&#x7167;&#x7247;&#x9009;&#x62E9;</span>
    <span class="hljs-keyword">if</span> !<span class="hljs-type">UIImagePickerController</span>.isSourceTypeAvailable(.<span class="hljs-type">PhotoLibrary</span>) {
        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#x65E0;&#x6CD5;&#x8BBF;&#x95EE;&#x7167;&#x7247;&#x5E93;&quot;</span>)
        <span class="hljs-keyword">return</span>
    }
}
</code></pre>
<ul>
<li>&#x8BBF;&#x95EE;&#x76F8;&#x518C;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x8BBF;&#x95EE;&#x76F8;&#x518C;</span>
<span class="hljs-keyword">let</span> picker = <span class="hljs-type">UIImagePickerController</span>()
presentViewController(picker, animated: <span class="hljs-built_in">true</span>, completion: <span class="hljs-built_in">nil</span>)
</code></pre>
<ul>
<li>&#x8BBE;&#x7F6E;&#x4EE3;&#x7406;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x4EE3;&#x7406;</span>
picker.delegate = <span class="hljs-keyword">self</span>
</code></pre>
<ul>
<li>&#x9075;&#x5B88;&#x534F;&#x8BAE;&#x5E76;&#x5B9E;&#x73B0;&#x65B9;&#x6CD5;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// MARK: - UIImagePickerControllerDelegate, UINavigationControllerDelegate</span>
<span class="hljs-class"><span class="hljs-keyword">extension</span> <span class="hljs-title">PictureSelectorViewController</span>: <span class="hljs-title">UIImagePickerControllerDelegate</span>, <span class="hljs-title">UINavigationControllerDelegate</span> </span>{

    <span class="hljs-comment">/// &#x9009;&#x4E2D;&#x5A92;&#x4F53;&#x4EE3;&#x7406;&#x65B9;&#x6CD5;</span>
    <span class="hljs-comment">///</span>
    <span class="hljs-comment">/// - parameter picker: &#x7167;&#x7247;&#x9009;&#x62E9;&#x5668;</span>
    <span class="hljs-comment">/// - parameter info:   &#x4FE1;&#x606F;&#x5B57;&#x5178; allowsEditing = true &#x9002;&#x5408;&#x9009;&#x62E9;&#x5934;&#x50CF;</span>
    <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">imagePickerController</span><span class="hljs-params">(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])</span> </span>{
        <span class="hljs-built_in">print</span>(info)

        dismissViewControllerAnimated(<span class="hljs-built_in">true</span>, completion: <span class="hljs-built_in">nil</span>)
    }
}
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x4E00;&#x65E6;&#x5B9E;&#x73B0;&#x4E86;&#x4EE3;&#x7406;&#x65B9;&#x6CD5;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x7528;&#x4EE3;&#x7801; <code>dismiss</code> &#x63A7;&#x5236;&#x5668;</p>
</blockquote>
<h4 id="%E8%AE%BE%E7%BD%AE%E5%9B%BE%E7%89%87%E6%95%B0%E6%8D%AE%E6%BA%90">&#x8BBE;&#x7F6E;&#x56FE;&#x7247;&#x6570;&#x636E;&#x6E90;</h4>
<ul>
<li>&#x5B9A;&#x4E49;&#x7167;&#x7247;&#x6570;&#x7EC4;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x7167;&#x7247;&#x6570;&#x7EC4;</span>
private lazy <span class="hljs-keyword">var</span> pictures = [<span class="hljs-type">UIImage</span>]()
</code></pre>
<ul>
<li>&#x5728;&#x4EE3;&#x7406;&#x65B9;&#x6CD5;&#x4E2D;&#x63D2;&#x5165;&#x7167;&#x7247;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">let</span> image = info[<span class="hljs-type">UIImagePickerControllerOriginalImage</span>] <span class="hljs-keyword">as</span>! <span class="hljs-type">UIImage</span>

pictures.append(image)
collectionView?.reloadData()

dismissViewControllerAnimated(<span class="hljs-built_in">true</span>, completion: <span class="hljs-built_in">nil</span>)
</code></pre>
<ul>
<li>&#x5728; cell &#x4E2D;&#x6DFB;&#x52A0; <code>image</code> &#x5C5E;&#x6027;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x7167;&#x7247;</span>
private <span class="hljs-keyword">var</span> image: <span class="hljs-type">UIImage</span>? {
    <span class="hljs-keyword">didSet</span> {
        addButton.setImage(image, forState: .<span class="hljs-type">Normal</span>)
    }
}
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x6570;&#x636E;&#x6E90;&#x4E2D;&#x7684;&#x56FE;&#x50CF;&#x6570;&#x91CF;&#x51FD;&#x6570;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">override</span> <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">collectionView</span><span class="hljs-params">(collectionView: UICollectionView, numberOfItemsInSection section: Int)</span> -&gt; <span class="hljs-title">Int</span> </span>{
    <span class="hljs-keyword">return</span> pictures.<span class="hljs-built_in">count</span> + <span class="hljs-number">1</span>
}
</code></pre>
<blockquote>
<p>&#x4FDD;&#x8BC1;&#x672B;&#x5C3E;&#x6709;&#x4E00;&#x4E2A;&#x52A0;&#x53F7;&#x6309;&#x94AE;&#x6DFB;&#x52A0;&#x7167;&#x7247;</p>
</blockquote>
<ul>
<li>&#x5728;&#x6570;&#x636E;&#x6E90;&#x65B9;&#x6CD5;&#x4E2D;&#x8BBE;&#x7F6E;&#x56FE;&#x50CF;</li>
</ul>
<pre><code class="lang-swift">cell.image = (indexPath.item == pictures.<span class="hljs-built_in">count</span>) ? <span class="hljs-built_in">nil</span> : pictures[indexPath.item]
</code></pre>
<ul>
<li>&#x6269;&#x5C55; <code>image</code> &#x5C5E;&#x6027;&#x7684; <code>didSet</code> &#x51FD;&#x6570;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x7167;&#x7247;</span>
private <span class="hljs-keyword">var</span> image: <span class="hljs-type">UIImage</span>? {
    <span class="hljs-keyword">didSet</span> {
        addButton.setImage(image ?? <span class="hljs-type">UIImage</span>(named: <span class="hljs-string">&quot;compose_pic_add&quot;</span>), forState: .<span class="hljs-type">Normal</span>)
        addButton.setImage(image ?? <span class="hljs-type">UIImage</span>(named: <span class="hljs-string">&quot;compose_pic_add_highlighted&quot;</span>), forState: .<span class="hljs-type">Highlighted</span>)
    }
}
</code></pre>
<h3 id="%E7%BB%86%E8%8A%82%E5%A4%84%E7%90%86">&#x7EC6;&#x8282;&#x5904;&#x7406;</h3>
<h4 id="%E8%AE%B0%E5%BD%95%E7%94%A8%E6%88%B7%E7%82%B9%E5%87%BB%E6%8C%89%E9%92%AE%E7%9A%84%E7%B4%A2%E5%BC%95">&#x8BB0;&#x5F55;&#x7528;&#x6237;&#x70B9;&#x51FB;&#x6309;&#x94AE;&#x7684;&#x7D22;&#x5F15;</h4>
<ul>
<li>&#x5B9A;&#x4E49;&#x5F53;&#x524D;&#x9009;&#x4E2D;&#x7167;&#x7247;&#x7D22;&#x5F15;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x5F53;&#x524D;&#x9009;&#x4E2D;&#x7167;&#x7247;&#x7D22;&#x5F15;</span>
private <span class="hljs-keyword">var</span> currentIndex = <span class="hljs-number">0</span>
</code></pre>
<ul>
<li>&#x5728;&#x4EE3;&#x7406;&#x65B9;&#x6CD5;&#x4E2D;&#x8BB0;&#x5F55;&#x5F53;&#x524D;&#x7528;&#x6237;&#x70B9;&#x51FB; cell &#x7684;&#x7D22;&#x5F15;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x8BB0;&#x5F55;&#x5F53;&#x524D;&#x7528;&#x6237;&#x9009;&#x4E2D;&#x7D22;&#x5F15;</span>
currentIndex = collectionView!.indexPathForCell(cell)!.item
</code></pre>
<ul>
<li>&#x5728;&#x7167;&#x7247;&#x9009;&#x62E9;&#x63A7;&#x5236;&#x5668;&#x7684;&#x4EE3;&#x7406;&#x65B9;&#x6CD5;&#x4E2D;&#x8BBE;&#x7F6E;&#x5BF9;&#x5E94;&#x7684;&#x56FE;&#x50CF;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">if</span> currentIndex &lt; pictures.<span class="hljs-built_in">count</span> {
    pictures[currentIndex] = image
} <span class="hljs-keyword">else</span> {
    pictures.append(image)
}
collectionView?.reloadData()
</code></pre>
<h4 id="%E8%AE%BE%E7%BD%AE%E7%85%A7%E7%89%87%E5%A1%AB%E5%85%85%E6%A8%A1%E5%BC%8F">&#x8BBE;&#x7F6E;&#x7167;&#x7247;&#x586B;&#x5145;&#x6A21;&#x5F0F;</h4>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x7167;&#x7247;&#x586B;&#x5145;&#x6A21;&#x5F0F;</span>
addButton.imageView?.contentMode = .<span class="hljs-type">ScaleAspectFill</span>
</code></pre>
<h4 id="%E5%88%A0%E9%99%A4%E7%85%A7%E7%89%87">&#x5220;&#x9664;&#x7167;&#x7247;</h4>
<ul>
<li>&#x5220;&#x9664;&#x7167;&#x7247;&#x64CD;&#x4F5C;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x5220;&#x9664;&#x7167;&#x7247;</span>
private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">pictureSelectorViewCellDidRemove</span><span class="hljs-params">(cell: PictureSelectorViewCell)</span> </span>{

    guard <span class="hljs-keyword">let</span> indexPath = collectionView?.indexPathForCell(cell) <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span>
    }

    pictures.removeAtIndex(indexPath.item)
    collectionView?.deleteItemsAtIndexPaths([indexPath])
}
</code></pre>
<ul>
<li>&#x9ED8;&#x8BA4;&#x9690;&#x85CF;&#x5220;&#x9664;&#x6309;&#x94AE;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x7167;&#x7247;</span>
private <span class="hljs-keyword">var</span> image: <span class="hljs-type">UIImage</span>? {
    <span class="hljs-keyword">didSet</span> {
        addButton.setImage(image ?? <span class="hljs-type">UIImage</span>(named: <span class="hljs-string">&quot;compose_pic_add&quot;</span>), forState: .<span class="hljs-type">Normal</span>)
        addButton.setImage(image ?? <span class="hljs-type">UIImage</span>(named: <span class="hljs-string">&quot;compose_pic_add_highlighted&quot;</span>), forState: .<span class="hljs-type">Highlighted</span>)

        removeButton.hidden = (image == <span class="hljs-built_in">nil</span>)
    }
}
</code></pre>
<h4 id="%E8%AE%BE%E7%BD%AE%E6%9C%80%E5%A4%9A%E9%80%89%E6%8B%A9%E7%85%A7%E7%89%87%E6%95%B0%E9%87%8F">&#x8BBE;&#x7F6E;&#x6700;&#x591A;&#x9009;&#x62E9;&#x7167;&#x7247;&#x6570;&#x91CF;</h4>
<ul>
<li>&#x5B9A;&#x4E49;&#x6700;&#x591A;&#x7167;&#x7247;&#x5E38;&#x91CF;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x6700;&#x5927;&#x7167;&#x7247;&#x6570;&#x91CF;</span>
private <span class="hljs-keyword">let</span> <span class="hljs-type">WBPictureSelectorViewMaxPictureCount</span> = <span class="hljs-number">9</span>
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x6570;&#x636E;&#x6E90;&#x65B9;&#x6CD5;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// MARK: &#x6570;&#x636E;&#x6E90;</span>
<span class="hljs-keyword">override</span> <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">collectionView</span><span class="hljs-params">(collectionView: UICollectionView, numberOfItemsInSection section: Int)</span> -&gt; <span class="hljs-title">Int</span> </span>{
    <span class="hljs-keyword">return</span> pictures.<span class="hljs-built_in">count</span> + (pictures.<span class="hljs-built_in">count</span> &lt; <span class="hljs-type">WBPictureSelectorViewMaxPictureCount</span> ? <span class="hljs-number">1</span> : <span class="hljs-number">0</span>)
}
</code></pre>
<h3 id="%E5%86%85%E5%AD%98%E5%A4%84%E7%90%86">&#x5185;&#x5B58;&#x5904;&#x7406;</h3>
<ul>
<li>&#x7F29;&#x653E;&#x56FE;&#x7247;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-class"><span class="hljs-keyword">extension</span> <span class="hljs-title">UIImage</span> </span>{

    <span class="hljs-comment">/// &#x5C06;&#x56FE;&#x50CF;&#x7F29;&#x653E;&#x5230;&#x6307;&#x5B9A;&#x5BBD;&#x5EA6;</span>
    <span class="hljs-comment">///</span>
    <span class="hljs-comment">/// - parameter width: &#x6307;&#x5B9A;&#x5BBD;&#x5EA6;&#xFF0C;&#x5982;&#x679C;&#x56FE;&#x7247;&#x5C3A;&#x5BF8;&#x6BD4;&#x6307;&#x5B9A;&#x5BBD;&#x5EA6;&#x5C0F;&#xFF0C;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;</span>
    <span class="hljs-comment">///</span>
    <span class="hljs-comment">/// - returns: &#x7B49;&#x6BD4;&#x4F8B;&#x7F29;&#x653E;&#x540E;&#x7684;&#x56FE;&#x50CF;</span>
    <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">scaleImage</span><span class="hljs-params">(width: CGFloat)</span> -&gt; <span class="hljs-title">UIImage</span> </span>{

        <span class="hljs-comment">// 1. &#x5224;&#x65AD;&#x56FE;&#x50CF;&#x5C3A;&#x5BF8;</span>
        <span class="hljs-keyword">if</span> size.width &lt; width {
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">self</span>
        }

        <span class="hljs-comment">// 2. &#x8BA1;&#x7B97;&#x6BD4;&#x4F8B;</span>
        <span class="hljs-keyword">let</span> height = size.height * width / size.width
        <span class="hljs-keyword">let</span> rect = <span class="hljs-type">CGRect</span>(x: <span class="hljs-number">0</span>, y: <span class="hljs-number">0</span>, width: width, height: height)

        <span class="hljs-comment">// 3. &#x6838;&#x5FC3;&#x7ED8;&#x56FE;</span>
        <span class="hljs-comment">// 1&gt; &#x5F00;&#x542F;&#x4E0A;&#x4E0B;&#x6587;</span>
        <span class="hljs-type">UIGraphicsBeginImageContext</span>(rect.size)

        <span class="hljs-comment">// 2&gt; &#x7ED8;&#x56FE;</span>
        drawInRect(rect)

        <span class="hljs-comment">// 3&gt; &#x83B7;&#x5F97;&#x7ED3;&#x679C;</span>
        <span class="hljs-keyword">let</span> result = <span class="hljs-type">UIGraphicsGetImageFromCurrentImageContext</span>()

        <span class="hljs-comment">// 4&gt; &#x5173;&#x95ED;&#x4E0A;&#x4E0B;&#x6587;</span>
        <span class="hljs-type">UIGraphicsEndImageContext</span>()

        <span class="hljs-comment">// 5&gt; &#x8FD4;&#x56DE;&#x7ED3;&#x679C;</span>
        <span class="hljs-keyword">return</span> result
    }
}
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x7167;&#x7247;&#x9009;&#x62E9;&#x63A7;&#x5236;&#x5668;&#x4EE3;&#x7406;&#x65B9;&#x6CD5;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x9009;&#x4E2D;&#x5A92;&#x4F53;&#x4EE3;&#x7406;&#x65B9;&#x6CD5;</span>
<span class="hljs-comment">///</span>
<span class="hljs-comment">/// - parameter picker: &#x7167;&#x7247;&#x9009;&#x62E9;&#x5668;</span>
<span class="hljs-comment">/// - parameter info:   &#x4FE1;&#x606F;&#x5B57;&#x5178; allowsEditing = true &#x9002;&#x5408;&#x9009;&#x62E9;&#x5934;&#x50CF;</span>
<span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">imagePickerController</span><span class="hljs-params">(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])</span> </span>{

    <span class="hljs-keyword">let</span> image = info[<span class="hljs-type">UIImagePickerControllerOriginalImage</span>] <span class="hljs-keyword">as</span>! <span class="hljs-type">UIImage</span>
    <span class="hljs-keyword">let</span> scaleImage = image.scaleImage(<span class="hljs-number">300</span>)

    <span class="hljs-keyword">if</span> currentIndex &lt; pictures.<span class="hljs-built_in">count</span> {
        pictures[currentIndex] = scaleImage
    } <span class="hljs-keyword">else</span> {
        pictures.append(scaleImage)
    }
    collectionView?.reloadData()

    dismissViewControllerAnimated(<span class="hljs-built_in">true</span>, completion: <span class="hljs-built_in">nil</span>)
}
</code></pre>
<h2 id="%E6%95%B4%E5%90%88%E7%85%A7%E7%89%87%E9%80%89%E6%8B%A9%E6%8E%A7%E5%88%B6%E5%99%A8">&#x6574;&#x5408;&#x7167;&#x7247;&#x9009;&#x62E9;&#x63A7;&#x5236;&#x5668;</h2>
<h3 id="%E5%87%86%E5%A4%87-%E6%96%87%E4%BB%B6">&#x51C6;&#x5907; &#x6587;&#x4EF6;</h3>
<ul>
<li>&#x5C06; <code>PhotoSelector</code> &#x62D6;&#x62FD;&#x81F3;&#x9879;&#x76EE;</li>
<li>&#x5C06; <code>UIImage+Extension.swift</code> &#x62D6;&#x62FD;&#x81F3;&#x9879;&#x76EE;</li>
</ul>
<h3 id="%E6%95%B4%E5%90%88%E7%85%A7%E7%89%87%E9%80%89%E6%8B%A9%E6%8E%A7%E5%88%B6%E5%99%A8">&#x6574;&#x5408;&#x7167;&#x7247;&#x9009;&#x62E9;&#x63A7;&#x5236;&#x5668;</h3>
<ul>
<li>&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;&#x5C5E;&#x6027;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x7167;&#x7247;&#x9009;&#x62E9;&#x63A7;&#x5236;&#x5668;</span>
private lazy <span class="hljs-keyword">var</span> pictureSelectorViewController = <span class="hljs-type">PictureSelectorViewController</span>()
</code></pre>
<ul>
<li>&#x51C6;&#x5907;&#x7167;&#x7247;&#x89C6;&#x56FE;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">/// &#x51C6;&#x5907;&#x7167;&#x7247;&#x89C6;&#x56FE;</span>
private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">preparePictureView</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-comment">// &#x6DFB;&#x52A0;&#x89C6;&#x56FE;</span>
    view.addSubview(pictureSelectorViewController.view)

    <span class="hljs-comment">// &#x81EA;&#x52A8;&#x5E03;&#x5C40;</span>
    pictureSelectorViewController.view.snp_makeConstraints { (make) -&gt; <span class="hljs-type">Void</span> <span class="hljs-keyword">in</span>
        make.bottom.equalTo(view.snp_bottom)
        make.<span class="hljs-keyword">left</span>.equalTo(view.snp_left)
        make.<span class="hljs-keyword">right</span>.equalTo(view.snp_right)
        make.height.equalTo(view.snp_height).multipliedBy(<span class="hljs-number">0.6</span>)
    }
}
</code></pre>
<blockquote>
<p>&#x8FD0;&#x884C;&#x6D4B;&#x8BD5;&#xFF0C;&#x53D1;&#x73B0;&#x9009;&#x4E2D;&#x7167;&#x7247;&#x7ED3;&#x675F;&#x540E;&#xFF0C;&#x63D0;&#x793A;&#x9519;&#x8BEF;&#xFF1A;</p>
</blockquote>
<p>Presenting view controllers on detached view controllers is discouraged </p>
<ul>
<li>&#x6DFB;&#x52A0;&#x5B50;&#x63A7;&#x5236;&#x5668;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x6DFB;&#x52A0;&#x5B50;&#x63A7;&#x5236;&#x5668;</span>
addChildViewController(pictureSelectorViewController)
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x7167;&#x7247;&#x9009;&#x62E9;&#x89C6;&#x56FE;&#x5C42;&#x6B21;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x6DFB;&#x52A0;&#x89C6;&#x56FE;</span>
view.insertSubview(pictureSelectorViewController.view, belowSubview: toolbar)
</code></pre>
<blockquote>
<p>&#x8FD0;&#x884C;&#x4F1A;&#x53D1;&#x73B0;&#x7167;&#x7247;&#x9009;&#x62E9;&#x89C6;&#x56FE;&#x8DD1;&#x5230;&#x4E86; textView &#x548C; toolBar &#x7684;&#x540E;&#x9762;</p>
</blockquote>
<h4 id="%E9%87%8D%E5%BB%BA%E6%8E%A7%E4%BB%B6%E5%B8%83%E5%B1%80">&#x91CD;&#x5EFA;&#x63A7;&#x4EF6;&#x5E03;&#x5C40;</h4>
<ul>
<li>&#x4FEE;&#x6539;&#x7167;&#x7247;&#x9009;&#x62E9;&#x89C6;&#x56FE;&#x7684;&#x9AD8;&#x5EA6;</li>
</ul>
<pre><code class="lang-swift">make.height.equalTo(<span class="hljs-number">0</span>)
</code></pre>
<ul>
<li>&#x5728;&#x9009;&#x62E9;&#x7167;&#x7247;&#x76D1;&#x542C;&#x65B9;&#x6CD5;&#x4E2D;&#x91CD;&#x5EFA;&#x63A7;&#x4EF6;&#x7D22;&#x5F15;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-comment">// &#x9009;&#x62E9;&#x7167;&#x7247;</span>
<span class="hljs-preprocessor">@objc</span> private <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">selectPhoto</span><span class="hljs-params">()</span> </span>{

    <span class="hljs-keyword">if</span> pictureSelectorViewController.view.bounds.height == <span class="hljs-number">0</span> {
        <span class="hljs-comment">// &#x4FEE;&#x6539;&#x5E03;&#x5C40;&#x9AD8;&#x5EA6;</span>
        pictureSelectorViewController.view.snp_remakeConstraints { (make) -&gt; <span class="hljs-type">Void</span> <span class="hljs-keyword">in</span>
            make.bottom.equalTo(view.snp_bottom)
            make.<span class="hljs-keyword">left</span>.equalTo(view.snp_left)
            make.<span class="hljs-keyword">right</span>.equalTo(view.snp_right)
            make.height.equalTo(view.snp_height).multipliedBy(<span class="hljs-number">0.6</span>)
        }
        <span class="hljs-comment">// &#x4FEE;&#x6539;&#x6587;&#x672C;&#x89C6;&#x56FE;&#x7684;&#x5E95;&#x90E8;&#x7EA6;&#x675F;</span>
        textView.snp_remakeConstraints { (make) -&gt; <span class="hljs-type">Void</span> <span class="hljs-keyword">in</span>
            make.top.equalTo(view.snp_top)
            make.<span class="hljs-keyword">left</span>.equalTo(view.snp_left)
            make.<span class="hljs-keyword">right</span>.equalTo(view.snp_right)
            make.bottom.equalTo(pictureSelectorViewController.view.snp_top)
        }

        <span class="hljs-type">UIView</span>.animateWithDuration(<span class="hljs-number">0.25</span>, animations: { () -&gt; <span class="hljs-type">Void</span> <span class="hljs-keyword">in</span>
            <span class="hljs-keyword">self</span>.view.layoutIfNeeded()
        })
    }
}
</code></pre>
<ul>
<li>&#x5173;&#x95ED;&#x952E;&#x76D8;</li>
</ul>
<pre><code class="lang-swift">textView.resignFirstResponder()
</code></pre>
<blockquote>
<p>&#x8FD0;&#x884C;&#x6D4B;&#x8BD5;</p>
</blockquote>
<ul>
<li>&#x8C03;&#x6574; <code>viewDidAppear</code> &#x5982;&#x679C;&#x5DF2;&#x7ECF;&#x663E;&#x793A;&#x7167;&#x7247;&#x9009;&#x62E9;&#x89C6;&#x56FE;&#xFF0C;&#x5219;&#x4E0D;&#x518D;&#x6FC0;&#x6D3B;&#x952E;&#x76D8;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">override</span> <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">viewDidAppear</span><span class="hljs-params">(animated: Bool)</span> </span>{
    <span class="hljs-keyword">super</span>.viewDidAppear(animated)

    <span class="hljs-keyword">if</span> pictureSelectorViewController.view.bounds.height == <span class="hljs-number">0</span> {
        textView.becomeFirstResponder()
    }
}
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../compose/setup ui.html" class="navigation navigation-prev " aria-label="Previous page: 搭建界面"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../compose/post status.html" class="navigation navigation-next " aria-label="Next page: 发布微博"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
